#include<bits/stdc++.h>
using namespace std;
int T,n,m,l,v,s1,s2,maxn=-1,minn=1,wxd;
int a[100010],b[100010],c[100010],d[100010];
int dis[25],vis[25];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    scanf("%d",&T);
    while(T--){
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		memset(c,0,sizeof(c));
		memset(d,0,sizeof(d));
		s1=s2=wxd=0;
		scanf("%d%d%d%d",&n,&m,&l,&v);
		for(int i=1;i<=n;i++){
			scanf("%d%d%d",&a[i],&b[i],&c[i]);
			maxn=max(maxn,c[i]);
			minn=min(minn,c[i]);
		}
		for(int i=1;i<=m;i++){
			scanf("%d",&d[i]);
			wxd=max(wxd,d[i]);
		}
		sort(d+1,d+m+1);
		if(n<=20){
		    for(int i=1;i<=n;i++){
				if(c[i]==0){
					if(b[i]>v){
						s1++;
						for(int j=1;j<=m;j++){
							if(d[j]>=a[i]) {
								break;
							}
						}
					}
					continue;
				}
			    for(int j=1;j<=m;j++){
				    if(d[j]<a[i]) continue;
				    int a1=b[i]*b[i]+2*c[i]*(d[j]-a[i]);
				    int a2=v*v;
				    if(a1>a2){
						s1++;
						break;
				    }
			    }
		    }
		    s2=m;
		    printf("%d %d\n",s1,s2);
		    continue;
		}
		else{
			if(minn==1||maxn==-1){
				for(int i=1;i<=n;i++){
					for(int j=1;j<=m;j++){
						if(b[i]*b[i]+2*c[i]*(d[j]-a[i])>v*v) s1++,s2=1;
					}
				}
			}
			else {
			    for(int i=1;i<=n;i++){
				    if(b[i]>v&&a[i]<=wxd) s1++,s2=1;
			    }
		    }
		}
		printf("%d %d\n",s1,m-s2);
	}
    return 0;
}
